<link rel="stylesheet" href="${request.contextPath}/css/suredy-tree.css">
<div class="container-fluid suredy-form" style="padding-top: 0">
	<div class="row">	
	<form name="form" id="form">
	    
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">父节点</div>
					<input type="hidden" readonly="readonly" id="parentId" name="parentId" value="<#if parent??>${parent.id}</#if>" />
					<input type="text" class="form-control" readonly="readonly" id="parentName"  value="<#if parent??>${parent.text}</#if>" />
					<div class="input-group-addon btn btn-default btn-load-menu-tree" data-toggle="collapse" href="#menu-tree" aria-expanded="false" aria-controls="menu-tree">
						<i class="icon-sitemap"></i>
					</div>
				</div>
			</div>
		
			<div class="collapse" id="menu-tree" style="border-top:1px solid #ddd; max-height:300px; overflow:auto;">
				<div class="suredy-tree normal menu-tree-for-parent" data-uri="menu-tree.do">加载中……</div>
			</div>

			<div class="row">&nbsp;</div>
		<#if menu??>
	
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">菜单文本</div>
					<input type="text" class="form-control" id="text" name="text" value="${menu.text}" />
					<input type="hidden" id="id" name="id" value="${menu.id}" />
				</div>
			</div>
		
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">链接地址</div>
					<input type="text" class="form-control" id="url" name="url" value="${menu.url}" />
				</div>
			</div>	
			
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">显示顺序</div>
					<input type="text" class="form-control" id="sort" name="sort" value="${menu.sort}"/>
				</div>
			</div>	
			
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">菜单图标</div>
					<input type="text" class="form-control" id="icon" name="icon" value="${menu.icon}"/>
				</div>
			</div>	
			
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">是否活动</div>
					<select class="form-control" id="active" name="active">
						<option value="true" <#if menu.active>selected="selected"</#if>>是</option>
						<option value="false" <#if !menu.active>selected="selected"</#if>>否 </option>		
					</select>
				</div>
			</div>			
	
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">是否收拢</div>
					<select class="form-control" id="collapse" name="collapse">
						<option value="true" <#if menu.collapse>selected="selected"</#if>>是</option>
						<option value="false" <#if !menu.collapse>selected="selected"</#if>>否 </option>				
					</select>
				</div>
			</div>				
						
		</#if>						
		<div class="text-center">
			<div class="btn btn-info" id="btn-save" >
				<i class="icon-save"></i> 保存
			</div>
		</div>	
	</form>	
	</div>
</div>
<script src="${request.contextPath}/js/suredy-tree.js"></script>
<script type="text/javascript">
	$(document).ready(function() {
		var parentTree = function() {
			$('.menu-tree-for-parent').tree('menu/tree',{
				click : function() {
					$('#parentName').val($(this).text());
					var nodeData = $.suredy.tree.data($(this));
					
					
					if (nodeData.id) {
						$('#parentId').val(nodeData.id);
					} else {
						$('#parentId').val('');
					}
				}
			});
		};

		parentTree();

		
		$('#btn-save').click(function() {

			var text = $('#text').val();			
			
			if (text == '') {
				alert('请填写名称！');
				return;
			}


	
			$.ajax({
				url : 'menu/edit-save.do',
				dataType : 'json',
				type : 'POST',
				data : $('#form').serialize(),
				success : function(success) {
					if (!success) {
						alert('修改菜单失败！');
					} else if (!success.success) {
						alert('修改菜单失败！\n\n' + success.msg);
					} else {
						alert('修改菜单成功！');
						$.suredy.loadContent('menu/manager.do');
						$.suredy.closeModal();
					}
				},
				error : function(a, b, c) {
					alert('服务器错误! ' + b);
				}
			});
		});	
	});
</script>	
